#ifndef CDEVICECTRL_H
#define CDEVICECTRL_H

#include <QObject>
#include <pthread.h>
#include "global.h"
#include "log.h"
#include "libv4l2.h"
#include "libv4lconvert.h"

struct VideoBuffer {
        void   *start;
        size_t length;
};

class CDeviceCtrl : public QObject
{
    Q_OBJECT
public:
    explicit            CDeviceCtrl(QObject *parent = 0);
    ~CDeviceCtrl();

    int                 OpenDevice();
    int                 ReadAndDisplay();
    int                 CloseDevice();
    int                 GetDeviceHandle() {return fd;}
    PSDLMODULE          GetSdlModule(){return pSdlModule;}
    PTAVSDLYUVSURFACE   GetSurface(){return pSurface;}
    struct VideoBuffer *GetVideoBuffer(){return video_buffers;}
    bool                GetCapFlag() {return devam;}
    CDebugLog*          GetDebugLog(){ return pLog;}

protected:
    int                 ReadConfigure(const char *filename);

private:
    QObject*            parent;
    CDebugLog*          pLog;
    pthread_t           hThreadDisplayHandle;   //渲染线程句柄
    pthread_t           hThreadRecordHandle;    //录制线程句柄

    bool                devam;
    int                 fd;
    unsigned int        buffer_count;
    char                out_name[256];
    PSDLMODULE          pSdlModule;             //SDL资源
    PTAVSDLYUVSURFACE   pSurface;               //SDL资源

    struct VideoBuffer* video_buffers;

public:
    uint32_t            inputIndex;
    uint32_t            videoFrameRate;
    uint32_t            captureWidth,
    uint32_t            captureHeight;
    uint32_t            volume;
    uint32_t            audioFrequency;
    uint32_t            channel;
    uint32_t            pingTimes;
    uint32_t            pingInterval;
    uint32_t            masterEncoderPort; 
    uint32_t            backupEncoderPort;
    uint32_t            pingPort;
    QString             defaultPlayFile;
    QString             masterMuticastIp;
    QString             backupMuticastIp;
    QString             masterEncoderIp;
    QString             backupEncoderIp;
    QString             masterIp;
    QString             backupIp;
    bool                isFullScreen;
    bool                isMaster;
};

#endif // CDEVICECTRL_H
